var pic = 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fc-ssl.duitang.com%2Fuploads%2Fblog%2F202102%2F26%2F20210226073347_50f94.thumb.1000_0.jpeg&refer=http%3A%2F%2Fc-ssl.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1668131440&t=6df291a148cdb21289e91211d4daea32';
var vm = new Vue({
    el:'#app',
    data:{ //负责定义响应式数据
        btnArr:['综合排序','距离最近','销量最高','筛选'],
        list:[
            { name:'秋刀鱼',price:88,pic,count:1 },
            { name:'大黄鱼',price:777,pic,count:2 },
            { name:'皮皮虾',price:9,pic,count:3 },
        ]
    },
    methods:{ //负责定义方法
        add(item){
            item.count++;
        },
        sub(item){
            if( item.count > 1 )item.count--;
        },
        clean(){
            this.list = [];
        },
        mysort(index){
            if( index == 0 ){ //点击了第一个按钮
                this.list.sort((a,b)=>{
                    return a.price - b.price;
                })
            }
            else if( index == 2 ){ //点击了第三个按钮
                this.list.sort((a,b)=>{
                    return b.count - a.count;
                })
            }
        }
    }
})